package com.bigfire.dtm.starter.config;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.NoTypePermission;
import org.axonframework.serialization.Serializer;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * XStream配置
 * @author Damon S.
 * @version v1.0.1
 * @date 2019年12月04日 18:16
 */
@Configuration
public class AxonStreamConfigure {

    @Bean
    @Primary
    public Serializer serializer(XStream xStream) {
        return XStreamSerializer.builder().xStream(xStream).build();
    }

    @Bean
    XStream xstream(){
        XStream xstream = new XStream();
        // clear out existing permissions and set own ones
        xstream.addPermission(NoTypePermission.NONE);
        // allow any type from the same package
        xstream.allowTypesByWildcard(new String[] {
                "com.bigfire.dtm.**",
                "org.axonframework.**",
                "java.**",
                "com.thoughtworks.xstream.**"
        });
        return xstream;
    }
}
